package com.example.demo2_review.array_and_arrayList;

import com.example.demo2_review.pojo.common.TestPojo;
import org.springframework.util.StopWatch;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author zwp14
 * @create 2024/6/17 19:21
 * @description 数组和集合
 */
public class Demo2ArrayArrayList {
    public static void main(String[] args) {
        //数组
        arrayMethod();
        //集合
        listMethod();
    }

    /**
     * 集合
     */
    private static void listMethod() {
        /*
        * 不能包含基本类型
        * 只能包含对象类型
        * */
//        List<int> intList = new ArrayList<>();
        List<Integer> integerList = new ArrayList<>();
        List<TestPojo> testPojoList = new ArrayList<>();
    }

    /**
     * 数组
     */
    private static void arrayMethod() {
        //基本数据类型
        int[] intArray = new int[3];
        intArray[0] = 10;
        intArray[1] = 11;
        intArray[2] = 12;
        System.out.println("intArray = " + Arrays.toString(intArray));
        //对象
        String[] strArray = new String[3];
        strArray[0] = "20";
        strArray[1] = "21";
        strArray[2] = "22";
        System.out.println("strArray = " + Arrays.toString(strArray));
        //对象
        TestPojo[] testPojoArray = new TestPojo[3];
        testPojoArray[0] = TestPojo.builder()
                .age(30)
                .name("30").build();
        testPojoArray[1] = TestPojo.builder()
                .name("31")
                .age(31).build();
        testPojoArray[2] = TestPojo.builder()
                .age(32)
                .name("32").build();
        System.out.println("testPojoArray = " + Arrays.toString(testPojoArray));
        //集合
        var listArray = new List[2];
        List<TestPojo> testPojoList = new ArrayList<>();
        testPojoList.add(TestPojo.builder().age(40).name("40").build());
        testPojoList.add(TestPojo.builder().age(41).name("41").build());
        testPojoList.add(TestPojo.builder().age(42).name("42").build());
        List<TestPojo> testPojoList1 = new ArrayList<>();
        testPojoList1.add(TestPojo.builder().age(50).name("50").build());
        testPojoList1.add(TestPojo.builder().age(51).name("51").build());
        testPojoList1.add(TestPojo.builder().age(52).name("52").build());
        listArray[0] = testPojoList;
        listArray[1] = testPojoList1;
        System.out.println("listArray" + Arrays.toString(listArray));
        //spring计数器
        StopWatch stopWatch = new StopWatch("zwp");
        //hutool计数器
        cn.hutool.core.date.StopWatch test = new cn.hutool.core.date.StopWatch("test");

        test.start();
        stopWatch.start();
        for (TestPojo testPojo : testPojoList) {
            System.out.println("testPojo = " + testPojo);
        }
        stopWatch.stop();
        test.stop();

        String taskName = test.currentTaskName();
        int taskCount = test.getTaskCount();
        double totalTimeSeconds = test.getTotalTimeSeconds();
        long totalTimeMillis = test.getTotalTimeMillis();
        long totalTimeNanos = test.getTotalTimeNanos();
        System.out.println("taskName = " + taskName);
        System.out.println("totalTimeSeconds = " + totalTimeSeconds);
        System.out.println("totalTimeMillis = " + totalTimeMillis);
        System.out.println("totalTimeNanos = " + totalTimeNanos);
        System.out.println("taskCount = " + taskCount);
        System.out.println(test.prettyPrint());
        System.out.println(stopWatch.prettyPrint());



    }
}
